<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

   <script src="script/jquery-1.7.2.js">
    </script>

</head>
<body>
    <form name="link" method="get" align="center" style="margin-top:20%">
        <input type="text" value="" id="passwd"/>
        <button type="button" id="b" >提交</button>
    </form>
<script>
    $(document).ready(function(){
        $("#b").click(function(){
            var passwd = $("#passwd").val();
            var shortlink = getQueryString("short");
            $.ajax({
                type:"GET",
                url:" http://localhost:8080/verif/" + shortlink + "?auth=" + passwd,
                dataType:"json",
                success:function(data){
                    if(data.code === 200) {
                        window.location.replace(data.data.link);
                    }else if(data.code === 201) {
                        window.confirm(data.message);
                    }
                },
                error:function(jqXHR){
                    console.log("Error: "+jqXHR.status);
                }
            });
        });

        // 禁止回车事件
        $(this).keydown( function(e) {
            var key = window.event?e.keyCode:e.which;
            //alert(key.toString());
            if(key.toString() == "13"){
                return false;
            }
        });

    });

    function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location
            .search
            .substr(1)
            .match(reg);
        if (r != null)
            return unescape(r[2]);
        return null;
    }
</script>
</body>
</html>